﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Photon.SocketServer;
using Photon.SocketServer.Rpc;
using PhotonHostRuntimeInterfaces;
using WorldOfSuperpowers.Cache;
using WorldOfSuperpowers_COMMON;

namespace WorldOfSuperpowers
{
    public class MasterClientPeer:PeerBase
    {
        public string UserAccount;
        public MasterClientPeer(InitRequest initRequest) : base(initRequest)
        {
            MasterServer.log.Debug("收到新的连接");
            var ip = initRequest.RemoteIP;
            var port = initRequest.RemotePort;
            MasterServer.log.Debug("新的客户端连接,IP:"+ip+",端口:"+ port+",id:"+initRequest.ApplicationId+",version:"+initRequest.ClientVersion);
        }

        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            MasterServer.log.Debug("收到:" + operationRequest.OperationCode + "客户端请求消息");
            OperationCode code = (OperationCode) operationRequest.OperationCode;
            MasterServer.handlerDic[code].TranslateDic(operationRequest.Parameters,this,sendParameters);
            
            
        }

        protected override void OnDisconnect(DisconnectReason reasonCode, string reasonDetail)
        {
            MasterServer.log.Debug("断开连接");
            UserCache.RemovePlayerForOffline(UserAccount);
            UserAccount = "";
        }
    }
}
